<?php
/**
 * Created by PhpStorm.
 * User: shkj
 * Date: 2020/5/7
 * Time: 23:29
 */

namespace app\api\controller\v1;
use think\facade\Request;

use think\Db;
class Index extends Base{
  public function index()
    {
        //当天的收入
        $price = db('order')->whereTime('create_time', 'd')->sum('order_total_price');
        //用户数量
        $user = model('user')->count();
        //当天的订单数量
        $order = db('order')->whereTime('create_time', 'd')->count();
        $info = array(
            'price'=>$price,
            'user'=>$user,
            'order'=>$order
        );
        return_json(200,'成功',$info);
       
    }

     public function echarts()
    {

        $res = db('user')->field('create_time')->all();
        foreach ($res as $k => $v) {
            $time[] = date('Y-m-d', $v['create_time']);
        }

        foreach (array_count_values($time) as $k => $v) {
            $number[] = $v;
        }

        $time = array_unique($time);
        sort($time);

        $order = db('order')->field('create_time')->all();
        foreach ($order as $k => $v) {
            $times[] = date('Y-m-d', $v['create_time']);
            $times = array_unique($times);
            sort($times);

        }

        foreach ($times as $k=>$v){
           //查询当天的订单总价
            $price[] = Db::name('order')->whereBetweenTime('create_time', $v)->field('order_total_price')->sum('order_total_price');

        }
            $info = array('time' => $time, 'number' => $number, 'times' => $times,'price'=>$price);
            return_json(200,'成功',$info);

        }

}
?>